package com.lagou.module3.task4;

import java.util.Scanner;

/**
 * 1. 展示菜单
 * 2. Main方法入口
 * 3. 获取用户输入
 *    生成StudentData实例并调用相关方法
 *
 */
public class InputMenu {

    public static void main(String[] args) {
        StudentData studentData = StudentData.getInstance();
        Scanner sc = new Scanner(System.in);
        String ch;
        int index;

        while (!(ch = menu()).equalsIgnoreCase("EXIT")){
            switch (ch){
                case "1":
                    System.out.println("请依次输入姓名, 年龄, 学号:");
                    studentData.addElement(new Student(sc.next(), sc.nextInt(), sc.nextInt()));
                    break;
                case "2":
                    System.out.println("请输入需修改信息学生的学号:");
                    index = studentData.findElementIndex(sc.nextInt());
                    if (index == -1){
                        System.out.println("无此学号信息！");
                    }else{
                        System.out.println("请依次输入姓名, 年龄, 学号:");
                        studentData.setElement(index, new Student(sc.next(), sc.nextInt(), sc.nextInt()));
                    }
                    break;
                case "3":
                    System.out.println("请输入需要删除的学生的学号:");
                    studentData.removeElement(sc.nextInt());
                    break;
                case "4":
                    System.out.println("请输入需查找的学号信息:");
                    Student node = studentData.findElement(sc.nextInt());
                    if (node == null){
                        System.out.println("无此学号信息！");
                    }else{
                        System.out.println(node);
                    }
                    break;
                case "5":
                    studentData.traverse();
                    break;
                default:
                    System.out.println("输入错误，请重新选择选项！");
            }
        }
    }

    private static String menu() {
        System.out.println("***********************************************");
        System.out.println("****************学生信息管理系统****************");
        System.out.println("      操作选项     说明");
        System.out.println("--------------     -----------");
        System.out.println("         1         新增学生信息");
        System.out.println("         2         修改学生信息");
        System.out.println("         3         删除学生信息");
        System.out.println("         4         查找学生信息");
        System.out.println("         5         遍历学生信息");
        System.out.println("         EXIT      退出");
        System.out.println("***********************************************");
        Scanner sc = new Scanner(System.in);
        return sc.next().trim();
    }




}
